package com.example.sls.controller.teacher.pro;

import com.example.sls.pojo.teacher.pro.Pro;
import com.example.sls.service.teacher.pro.ProService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

//处理查询类题目

@RestController
@RequestMapping("/queryPro")
public class ProController {
    @Autowired
    private ProService proService;

    //添加题目
    @PostMapping("/addPro")
    Map<String,String> addPro(@RequestParam Map<String, String> params){

        Map<String,String> res = new HashMap<>();

        Integer setId = Integer.valueOf(params.get("setId"));
        Integer proType = Integer.valueOf(params.get("proType"));
        String content = params.get("content");
        String correctSQL = params.get("correctSQL");

//        System.out.println("========");
//        System.out.println(setId);
//        System.out.println(proType);
//        System.out.println(content);
//        System.out.println(correctSQL);
//        System.out.println("========");

        if(proService.addPro(setId, proType, content, correctSQL)){
            res.put("error_message", "success");
        }
        else{
            res.put("error_message", "failed");
        }
        return res;
    }



    //通过setId查询指定题集中所有题目(要分页)
    @GetMapping("/getPageInfoBySetId/{setId}/{pageNum}/{pageSize}")
    public PageInfo<Pro> getPageInfoBySetId(@PathVariable("setId") Integer setId, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){

//        System.out.println("========");
//        System.out.println("setId: " + setId);
//        System.out.println("pageNum: " + pageNum);
//        System.out.println("pageSize: " + pageSize);
//        System.out.println("========");

        return proService.getPageInfoBySetId(setId,pageNum,pageSize);
    }


    //通过id获取题目所有信息
    @GetMapping("/getProInfoById/{id}")
    public Pro getProInfoById(@PathVariable("id") Integer id){
        return proService.getProInfoById(id);
    }





}
